package GUI;

import MyLib.Comvar;
import MyThread.listenRequest;
import MyLib.ShowCenterScreen;
import MyThread.DownLoadFile;
import Object.*;


import java.awt.Font;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author QuangHau
 */
public class Main extends javax.swing.JFrame {

    private Torrent torrenFile = null;
    /**
     * Creates new form Main
     */
    private listenRequest lrThread = null;
    private DownLoadFile downLoadFileThread = null;

    public Main() {
        initComponents();
        ShowCenterScreen.show(this);
        lrThread = new listenRequest(tbChunk);
        lrThread.start();
        Comvar.writeLog(1, Main.class.getName(), "BEGIN PROGRAM");
    }

    private boolean close() {
        if (downLoadFileThread != null && downLoadFileThread.isAlive() && !downLoadFileThread.stopDownloadFile()) {
            JOptionPane.showMessageDialog(null, "Writing file, can't stop.", "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        lrThread.stop();
        return true;
    }

    public Object[] columnNames() {
        return new Object[]{"Chunk", "Peer", "Host", "Status"};
    }

    public Object[][] rowData() {
        Object[][] arrO = null;
        if (torrenFile != null) {
            int n = torrenFile.getChunks().size();
            arrO = new Object[n][4];
            for (int i = 0; i < n; i++) {
                arrO[i][0] = torrenFile.getChunks().get(i).getId();
                arrO[i][1] = null;
                arrO[i][2] = null;
                arrO[i][3] = null;
            }
        }
        return arrO;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbStopText = new javax.swing.JLabel();
        lbStrartText = new javax.swing.JLabel();
        lbStart = new javax.swing.JLabel();
        lbStop = new javax.swing.JLabel();
        lbCreate = new javax.swing.JLabel();
        lbAddText = new javax.swing.JLabel();
        lbAdd = new javax.swing.JLabel();
        lbCreateText = new javax.swing.JLabel();
        lbSetting = new javax.swing.JLabel();
        lbSettingText = new javax.swing.JLabel();
        lbExit = new javax.swing.JLabel();
        lblbExitText = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtInfomation = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbChunk = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lbStopText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbStopText.setText("Stop");

        lbStrartText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbStrartText.setText("Start");

        lbStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/play.png"))); // NOI18N
        lbStart.setText("lbAdd");
        lbStart.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbStart.setEnabled(false);
        lbStart.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbStartMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbStartMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbStartMouseExited(evt);
            }
        });

        lbStop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/stop.png"))); // NOI18N
        lbStop.setText("lbAdd");
        lbStop.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbStop.setEnabled(false);
        lbStop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbStopMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbStopMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbStopMouseExited(evt);
            }
        });

        lbCreate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/split.png"))); // NOI18N
        lbCreate.setText("lbAdd");
        lbCreate.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbCreate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbCreateMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbCreateMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbCreateMouseExited(evt);
            }
        });

        lbAddText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbAddText.setText("Add");

        lbAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        lbAdd.setText("lbAdd");
        lbAdd.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbAddMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbAddMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbAddMouseExited(evt);
            }
        });

        lbCreateText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbCreateText.setText("Create File");

        lbSetting.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Setting.png"))); // NOI18N
        lbSetting.setText("lbAdd");
        lbSetting.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbSetting.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbSettingMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbSettingMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbSettingMouseExited(evt);
            }
        });

        lbSettingText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbSettingText.setText("Setting");

        lbExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/exit.png"))); // NOI18N
        lbExit.setText("lbAdd");
        lbExit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbExit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbExitMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbExitMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbExitMouseExited(evt);
            }
        });

        lblbExitText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblbExitText.setText("Exit");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbAddText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbStart, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbStrartText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbStop, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbStopText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbCreateText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbSetting, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbExit, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbSettingText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblbExitText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lbStart, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbStop, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbSetting, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbExit, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lbAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbAddText)
                    .addComponent(lbStrartText)
                    .addComponent(lbStopText)
                    .addComponent(lbCreateText)
                    .addComponent(lbSettingText)
                    .addComponent(lblbExitText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Infomation"));

        txtInfomation.setEditable(false);
        txtInfomation.setBackground(new java.awt.Color(240, 240, 240));
        txtInfomation.setColumns(20);
        txtInfomation.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        txtInfomation.setRows(5);
        txtInfomation.setWrapStyleWord(true);
        jScrollPane1.setViewportView(txtInfomation);

        tbChunk.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Chunk", "Peer", "Host", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tbChunk);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addComponent(jScrollPane2)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // <editor-fold defaultstate="collapsed" desc="Label Create">     
    private void lbCreateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbCreateMouseClicked
        if (lbCreate.isEnabled()) {
            CreateFile cr = new CreateFile(null, true);
            ShowCenterScreen.show(cr);
            cr.setVisible(true);
        }
    }//GEN-LAST:event_lbCreateMouseClicked

    private void lbCreateMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbCreateMouseEntered
        if (lbCreate.isEnabled()) {
            lbCreateText.setFont(new Font("Tahoma", 1, 11));
        }
    }//GEN-LAST:event_lbCreateMouseEntered

    private void lbCreateMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbCreateMouseExited
        if (lbCreate.isEnabled()) {
            lbCreateText.setFont(new Font("Tahoma", 0, 11));
        }
    }//GEN-LAST:event_lbCreateMouseExited
    // </editor-fold>   

    // <editor-fold defaultstate="collapsed" desc="Label Add">    
    private void lbAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbAddMouseClicked
        if (lbAdd.isEnabled()) {
            JFileChooser choose = new JFileChooser();
            FileNameExtensionFilter filter1 = new FileNameExtensionFilter("Torrent", "torrent");
            choose.setFileFilter(filter1);
            choose.setAcceptAllFileFilterUsed(false);

            if (choose.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                torrenFile = new Torrent(choose.getSelectedFile());
                txtInfomation.setText("");
                txtInfomation.append("File name: " + torrenFile.getName() + "\n");
                txtInfomation.append("Size: " + String.format("%.0f", torrenFile.getSize() / 1024) + " KB\n");
                txtInfomation.append("Chunk : " + torrenFile.getChunks().size() + "\n");
                TableModel tbMode = new DefaultTableModel(rowData(), columnNames()) {
                    @Override
                    public boolean isCellEditable(int rowIndex, int mColIndex) {
                        return false;
                    }
                };
                tbChunk.setModel(tbMode);
                DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
                centerRenderer.setHorizontalAlignment(JLabel.CENTER);
                int rowNumber = tbChunk.getColumnCount();
                for (int i = 0; i < rowNumber; i++) {
                    tbChunk.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
                }

                lbStart.setEnabled(true);
            }
        }
    }//GEN-LAST:event_lbAddMouseClicked

    private void lbAddMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbAddMouseEntered
        if (lbAdd.isEnabled()) {
            lbAddText.setFont(new Font("Tahoma", 1, 11));
        }
    }//GEN-LAST:event_lbAddMouseEntered

    private void lbAddMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbAddMouseExited
        if (lbAdd.isEnabled()) {
            lbAddText.setFont(new Font("Tahoma", 0, 11));
        }
    }//GEN-LAST:event_lbAddMouseExited
    // </editor-fold>  

    // <editor-fold defaultstate="collapsed" desc="Label Start">     
    private void lbStartMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStartMouseClicked
        if (lbStart.isEnabled()) {
            StartDownload st = new StartDownload(null, true, torrenFile);
            ShowCenterScreen.show(st);
            st.setVisible(true);
//            txtInfomation.setText("");
//            txtInfomation.append("File name: " + torrenFile.getName() + "\n");
//            txtInfomation.append("Size: " + String.format("%.0f", torrenFile.getSize() / 1024) + " KB\n");
//            txtInfomation.append("Chunk : " + torrenFile.getChunks().size() + "\n");
            if (st.isDownload) {
                lbStop.setEnabled(true);
                lbAdd.setEnabled(false);
                lbStart.setEnabled(false);
                lbStrartText.setFont(new Font("Tahoma", 0, 11));
                Comvar.listChunkIP.clear();
                Comvar.stopFindChunk = false;
                for (int i = 0; i < torrenFile.getChunks().size(); i++) {
                    Comvar.listChunkIP.add(new ArrayList<InetAddress>());
                }
                for (int i = 0; i < tbChunk.getRowCount(); i++) {
                    tbChunk.setValueAt("Finding...", i, 3);
                }
                //tbChunk.setRowSelectionInterval(0, 0);
                downLoadFileThread = new DownLoadFile(torrenFile, st.path, st.numChunk, new Object[]{lbStop, lbAdd, txtInfomation, tbChunk, lbStart});
                downLoadFileThread.start();
            }
        }
    }//GEN-LAST:event_lbStartMouseClicked

    private void lbStartMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStartMouseEntered
        if (lbStart.isEnabled()) {
            lbStrartText.setFont(new Font("Tahoma", 1, 11));
        }
    }//GEN-LAST:event_lbStartMouseEntered

    private void lbStartMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStartMouseExited
        if (lbStart.isEnabled()) {
            lbStrartText.setFont(new Font("Tahoma", 0, 11));
        }
    }//GEN-LAST:event_lbStartMouseExited
    // </editor-fold>  

    // <editor-fold defaultstate="collapsed" desc="Label Stop"> 
    private void lbStopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStopMouseClicked
        if (lbStop.isEnabled()) {
            //downLoadFileThread.stopDownloadFile();
            if (!downLoadFileThread.stopDownloadFile()) {
                JOptionPane.showMessageDialog(null, "Writing file, can't stop.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_lbStopMouseClicked

    private void lbStopMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStopMouseEntered
        if (lbStop.isEnabled()) {
            lbStopText.setFont(new Font("Tahoma", 1, 11));
        }
    }//GEN-LAST:event_lbStopMouseEntered

    private void lbStopMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbStopMouseExited
        if (lbStop.isEnabled()) {
            lbStopText.setFont(new Font("Tahoma", 0, 11));
        }
    }//GEN-LAST:event_lbStopMouseExited
    // </editor-fold>  

    // <editor-fold defaultstate="collapsed" desc="Label Setting"> 
    private void lbSettingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbSettingMouseClicked
        if (lbSetting.isEnabled()) {
            Setting st = new Setting(null, true);
            ShowCenterScreen.show(st);
            st.setVisible(true);
        }
    }//GEN-LAST:event_lbSettingMouseClicked

    private void lbSettingMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbSettingMouseEntered
        if (lbSetting.isEnabled()) {
            lbSettingText.setFont(new Font("Tahoma", 1, 11));
        }
    }//GEN-LAST:event_lbSettingMouseEntered

    private void lbSettingMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbSettingMouseExited
        if (lbSetting.isEnabled()) {
            lbSettingText.setFont(new Font("Tahoma", 0, 11));
        }
    }//GEN-LAST:event_lbSettingMouseExited
    // </editor-fold>  

    // <editor-fold defaultstate="collapsed" desc="Label Exit"> 
    private void lbExitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbExitMouseClicked
        if(close()){
            Comvar.writeLog(1, Main.class.getName(), "END PROGRAM");
            System.exit(0);      
        }
    }//GEN-LAST:event_lbExitMouseClicked

    private void lbExitMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbExitMouseEntered
        lblbExitText.setFont(new Font("Tahoma", 1, 11));
    }//GEN-LAST:event_lbExitMouseEntered

    private void lbExitMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbExitMouseExited
        lblbExitText.setFont(new Font("Tahoma", 0, 11));
    }//GEN-LAST:event_lbExitMouseExited

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if(close()){
            Comvar.writeLog(1, Main.class.getName(), "END PROGRAM");
            System.exit(0);      
        }
        
    }//GEN-LAST:event_formWindowClosing
    // </editor-fold>  

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbAdd;
    private javax.swing.JLabel lbAddText;
    private javax.swing.JLabel lbCreate;
    private javax.swing.JLabel lbCreateText;
    private javax.swing.JLabel lbExit;
    private javax.swing.JLabel lbSetting;
    private javax.swing.JLabel lbSettingText;
    private javax.swing.JLabel lbStart;
    private javax.swing.JLabel lbStop;
    private javax.swing.JLabel lbStopText;
    private javax.swing.JLabel lbStrartText;
    private javax.swing.JLabel lblbExitText;
    private javax.swing.JTable tbChunk;
    private javax.swing.JTextArea txtInfomation;
    // End of variables declaration//GEN-END:variables
}
